package model.action;

import java.util.ArrayList;
import java.util.List;
import datacontainer.ImmuTable;


/**
 * Class is empty. We created it to preserve some semblence of a
 * hierarchy that makes logical sense.
 * 
 * To extend ColumnAction, make sure that the class ends with "Column"
 * ex) AddColumn, RemoveColumn etc.
 * 
 * @author Michael Deng
 * @author Jei Min Yoo
 * 
 */
public abstract class ColumnAction extends AbstractAction {

    private String myColumnName;

    @Override
    public void setInput (String column, List<String> conditions) {
        myColumnName = column;
    }

    /**
     * subclasses can use myColumnName variable with this method.
     * 
     * @return myColumnName
     */
    protected String getColumnName () {
        return myColumnName;
    }

    /**
     * Removes the column specified by the index from the workspace.
     * 
     * @param index
     */
    protected void removeColumn (ImmuTable workSpace, int index) {
        workSpace.getHeaders().remove(index);
        workSpace.getTypes().remove(index);
        workSpace.getData().remove(index);
    }

    /**
     * Adds the rawdata column specified by the index to the
     * end of the workspace.
     * 
     * @param columnIndex
     */
    protected void addColumn (ImmuTable workSpace, ImmuTable rawData, int columnIndex) {
        workSpace.getHeaders().add(rawData.getHeaders().get(columnIndex));
        workSpace.getTypes().add(rawData.getTypes().get(columnIndex));

        List<String> listToAdd = new ArrayList<String>();
        for (int j = 0; j < rawData.getColumn(columnIndex).size(); j++) {
            listToAdd.add(rawData.getColumn(columnIndex).get(j));
        }
        workSpace.getData().add(listToAdd);
    }
}
